layui.use(['form', 'jquery', 'layer', 'table', 'laydate', 'upload'], function() {
	var form = layui.form;
	var $ = layui.$;
	var table = layui.table;
	var layer = layui.layer;
	var laydate = layui.laydate;
	var upload = layui.upload;

	var lay_filter = 'tpl_site_config' + site_config_id;
	form.val(lay_filter, site_config_form_value);
	form.render();
	if(site_config_id > 0) {
		$('input[name="config_name"]').prop('readonly', true);
	} else {
		$('input[name="config_name"]').prop('readonly', false);
	}
	form.verify({
		config_name_check: function(value, item) {
			if(!new RegExp("^[a-zA-Z][a-zA-Z0-9_]*$").test(value)) {
				return '只能是字母，下划线，数字，且必须字母开头';
			}
		}
	});
	// 监听提交
	form.on('submit(submit_site_config)', function(data) {
		var field = data.field;
		var url = $('form[lay-filter="' + lay_filter + '"]').attr('action');
		send_info(url, field, function(data) {
			if(data.code == 0) {
				layer.msg('保存成功', {
					icon: 1
				});
				// 关闭当前页 刷新父页
				$('.layui-body .layui-tab[lay-filter="content"] li.layui-this .layui-tab-close').trigger('click');
				// 父页面点击
				$('.layui-body .layui-tab[lay-filter="content"] li[lay-id="site_config_list"]').trigger('click');
				// 表格重载
				table.reload('site_config_list');
			} else {
				layer.msg(data.msg, {
					icon: 2,
					anim: 6
				});
			}
		})
		return false;
	})

})